﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using AutumnEngine.Modules;
using System.Diagnostics;
using AutumnEngine;

namespace AutumnEngine.Modules
{
    /// <summary>
    /// Manages fonts and provides an easy system to choose fonts.
    /// </summary>
    public class FontManagerModule : Module
    {
        Dictionary<string, SpriteFont> fonts = new Dictionary<string, SpriteFont>();
        Dictionary<string, string> paths = new Dictionary<string, string>();
        
        /// <summary>
        /// Adds the font.
        /// </summary>
        /// <param name="name">The name of the font.</param>
        /// <param name="path">The path of the font.</param>
        public void AddFont(string name, string path)
        {
            try
            {
                paths.Add(name, path);
                fonts.Add(name, Engine.Modules.ContentManager.Load<SpriteFont>(path));
            }
            catch (Exception) { }
        }

        /// <summary>
        /// Gets the font.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        public SpriteFont GetFont(string name)
        {
            return fonts[name];
        }

        public string GetPathFromKey(string key)
        {
            return paths[key];
        }

        /// <summary>
        /// Creates this instance.
        /// </summary>
        public override void Create()
        {
            this.Removable = false;
            this.CanBeDisabled = false;
            base.Create();
        }

        /// <summary>
        /// Measures the string.
        /// </summary>
        /// <param name="content">The text to measure..</param>
        /// <param name="fontName">Name of the font.</param>
        /// <returns></returns>
        public Vector2 MeasureString(string content, string fontName)
        {
            return fonts[fontName].MeasureString(content);
        }
    }
}